#include "face_detection_gpu.h"

int main(int argc, char *argv[]) {
    if(argc != 3) {
        printf("Usage: face_detection_gpu [image] [classifier]\n");
        return 0;
    }

    IplImage *image = cvLoadImage(argv[1]);
    if(image == 0) {
        printf("image == NULL\n");
        return 0;
    }

    IplImage *gray_img = cvCreateImage(cvGetSize(image), IPL_DEPTH_8U, 1);
    cvCvtColor(image, gray_img, CV_BGR2GRAY);

    CvHaarClassifierCascade *cascade = (CvHaarClassifierCascade *)cvLoad(argv[2]);

    CvMemStorage* storage = cvCreateMemStorage(0);

    CvSeq *faces = FaceDetectionGPU(image, gray_img, cascade, storage, 1.2);

    if(faces != NULL) {
        for( int i = 0; i < faces->total; i++ ) {
            /* extract the rectangles only */
            CvRect face_rect = *(CvRect*)cvGetSeqElem( faces, i );
            cvRectangle( image, cvPoint(face_rect.x,face_rect.y),
                         cvPoint((face_rect.x+face_rect.width),
                                 (face_rect.y+face_rect.height)),
                         CV_RGB(255,0,0), 3 );
        }
    }

    cvSaveImage("result_gpu.png", image);

    cvReleaseImage(&gray_img);

    cvReleaseMemStorage( &storage );
}
